import {Component, OnInit, Input, Output, EventEmitter} from '@angular/core';
import {Todo} from '../model/todo-model';
import {TodoService} from '../todo-main/todo-main.service';

@Component({
    selector: 'app-todo-list',
    templateUrl: './todo-list.component.html',
    styleUrls: ['./todo-list.component.css']
})
export class TodoListComponent implements OnInit {

    @Input()
    public tableTitle: string;
    @Input()
    public completed: string;

    @Output()
    public doComplete = new EventEmitter<Todo>();

    public todoList: Todo[];

    constructor(
        public todoService: TodoService
    ) {

        todoService.change.subscribe((value: boolean) => {
            this.todoList = this.todoService.getList(this.completed === 'true');
        });

    }

    ngOnInit() {
        this.todoList = this.todoService.getList(this.completed === 'true');
    }


    public doChange(todo: Todo) {
        console.log('1===========');
        this.doComplete.emit(todo);
        console.log('2===========');
    }
}
